import {
	objDeepCopy,
	getDateString
} from "@/assets/js/common.js";

let Controller = {
	created() {
		this.init();
	},
	mounted() {

	},
	methods: {
		init() {
			this.getListMsg(this, this.$route.query.number);
		},
		//获取列表接口
		getListMsg(that, orderNumber) {
			var apiTest = this.apiTest;
			this.$ajax({
				method: 'post',
				url:apiTest+'/supplier/whWarehouseDetail/outAndInDetails',
				// url: '/api/whWarehouseDetail/outAndInDetails',
				data: {
					condition: {
						number: orderNumber
					},
				}
			}).then((res) => {
				that.Model.tab1TableData1 = [];
				that.Model.tab1TableData2 = [];
				var data = res.data;
				if (data.status == 200) {
					var obj = {};
					var obj2 = {};
					var result = data.result;
					if (result.status == 60) {
						that.Model.refundStep.step = [{
								title: '创建出库单',
								description: ""
							},
							{
								title: '待出库',
								description: ""
							},
							{
								title: '已作废',
								description: ""
							}
						]
						that.Model.refundStep.activeStep = 2
					} else {
						that.Model.refundStep.step = [{
								title: '创建出库单',
								description: ""
							},
							{
								title: '待出库',
								description: ""
							},
							{
								title: '已出库',
								description: ""
							},
							{
								title: '已完结',
								description: ""
							}
						]
						switch (result.status) {
							case 30:
								that.Model.refundStep.activeStep = 1
								break;
							case 40:
								that.Model.refundStep.activeStep = 2
								break;
							case 50:
								that.Model.refundStep.activeStep = 3
								break;
							default:
								break;
						}

					}

					/* tabFormInline */
					this.Model.tabFormInline = [{
							label: '调拨出库单号',
							value: result.number,
						},
						{
							label: '单据状态',
							value: result.status,
						},
					]
					
					/* tableFormInline */
					this.Model.tableFormInline = [{
							label: '出库单类型',
							value: result.type
						},
						{
							label: '调拨单号',
							value: result.originNumber
						},
						{
							label: '发货仓库',
							value: result.outWarehouseName
						},
						{
							label: '收货仓库',
							value: result.inWarehouseName
						},
						{
							label: '操作人',
							value: result.operatorName
						},
						{
							label: '备注',
							value: result.remark
						}
					]
					//应出 表格数据
					var listData = result.shouldSaleGoodsInfoVos;
					for (var i = 0; i < listData.length; i++) {
						obj = objDeepCopy(listData[i]);
						that.Model.tab1TableData1.push(obj)
					}
					//实出 表格数据
					var listData2 = result.actualSaleGoodsInfoVos;
					for (var i = 0; i < listData2.length; i++) {
						obj2 = objDeepCopy(listData2[i]);
						that.Model.tab1TableData2.push(obj2)
					}
					
				} else {
					that.tips(that, 'warning', data.msg);
				}

			});
		},

		//
		onDialogEdit() {

		},
		//
		toggleTableDetail() {

		},
		//返回上一级
		toInside() {
			this.$router.push({
				path: 'outsideAllocationStore',
				query: {

				}
			});
		},
		toggleTableDetail(val) {
			const obj = this.Model[val];
			if (obj.flag === true) {
				this.Model[val].src = require('@/assets/img/icon_collapse.png');
				this.Model[val].flag = false;
			} else {
				this.Model[val].src = require('@/assets/img/icon_unfold.png');
				this.Model[val].flag = true;
			}
		},
		onDialogEdit(flag, val) {
			// 			this.Model.editDialogFlag = flag;
			// 			var saleId = this.Model.saleId;	
			// 			if (flag === false) return;
			// 			const arr = this.Model[val];
			// 			this.Model.editDialogType = val;
			// 			this.Model.editDialogFormData = _.cloneDeep(arr);
		},
		selectedHighlight(data) {
			// 如果选中则添加高亮样式
			if (this.Model.TableSelectData.indexOf(data.row) > -1) {
				return {
					"background-color": "#FEF6EE"
				};
				return {}
			}
		},
		//合计
		getSummaries(param) {
			var that = this;
			const {
				columns,
				data
			} = param;
			const sums = [];
			columns.forEach((column, index) => {
				if (index === 0) {
					sums[index] = '总价';
					return;
				} else if (index === 6 || index === 7 || index === 8 || index === 10) {
					const values = data.map(item => Number(item[column.property]));
					sums[index] = values.reduce((prev, curr) => {
						const value = Number(curr);
						if (!isNaN(value)) {
							return prev + curr;
						} else {
							return prev;
						}
					}, 0);
					if (index === 10) {
						that.Model.totleGoodCount = sums[index];
					} else {

					}

				} else {
					sums[index] = '/';
				}
			});

			return sums;
		},
		warehousing(row) {
			this.Model.warehousingDialogStatus = row.status;
			this.Model.warehousingDialogFlag = true;
		},
		handleSelectionChange(val) {
			this.Model.TableSelectData = val;

		},
		handleCurrentChange(val) {
			this.Model.pager.params.pageIndex = val;
		},
		handleSizeChange(val) {
			this.Model.pager.params.pageSize = val;
		},
		cardClick(color) {
			this.Model.cardSelected = color;
		},
		showChild(val) {
			this.Model.searchFromData = val;
		},
		toSearch(val) {
			console.log(val)
		},
		toClear(val) {
			this.Model.searchFromData = this.Model.defaultSearchFromData;
		},
		toExport(val) {
			console.log(val);
		},
		onTabChange(val) {
			console.log(val, this.Model.activeTab)
			switch (val) {
				case 1:
					break;
				case 2:
					break;
				case 3:
					break;
			}
		},
		tips(that, type, message) {
			let duration;
			type == 'success' ? duration = 3000 : duration = 10000;
			that.$message({
				message: message,
				type: type,
				duration: duration
			});
		},
	},
	watch: {
		$route: {
			handler(newValue, oldValue) {
				if (newValue.query.number) {
					this.getListMsg(this, newValue.query.number);
				}
			},
			deep: true
		},

	},
	filters: {
		statusFilters: function(value) {
			let val;
			switch (value) {
				case 10:
					val = '待入库'
					break;
				case 20:
					val = '已入库'
					break;
				case 30:
					val = '待出库'
					break;
				case 40:
					val = '已出库'
					break;
				case 50:
					val = '已完结'
					break;
				case 60:
					val = '已作废'
					break;
				default:
					break;
			}
			return val
		}
	}
}
export default Controller;
